package com.henry.chatkit.utils

import android.os.Handler
import android.os.Looper

class BackgroundTasks {

    companion object {
        private var instance: BackgroundTasks? = null

        fun getInstance(): BackgroundTasks? {
            return instance
        }

        // 需要在主线程中初始化
        fun initInstance() {
            instance = BackgroundTasks()
        }
    }

    private val mHandler = Handler(Looper.getMainLooper()!!)

    fun runOnUiThread(runnable: Runnable?) {
        mHandler.post(runnable!!)
    }

    fun postDelayed(r: Runnable?, delayMillis: Long): Boolean {
        return mHandler.postDelayed(r!!, delayMillis)
    }

    fun getHandler(): Handler? {
        return mHandler
    }

}